import 'package:flutter/material.dart';
import 'package:projectfluttershengyihuatong/tool/extension_int.dart';
import '../tool/tool.dart';
import '../tab1/home.dart';
import '../tab2/question.dart';
import '../tab3/study.dart';
import '../tab4/news.dart';
import '../tab5/profile.dart';


class TabbarManager extends StatefulWidget {
  const TabbarManager({super.key});

  @override
  State<StatefulWidget> createState() {
    return TabbarManagerState();
  }
}

class TabbarManagerState extends State<TabbarManager>{
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }


  final List<Widget> _pages = [const HomePage(),const QuestionPage(),const  StudyPage(),const NewsPage(),const ProfilePage()];

  int _currentIndex = 0;
  @override
  Widget build(BuildContext context) {
    
    // TODO: implement build
    return Scaffold(
      body: _pages[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: const Color.fromARGB(1, 80, 220, 142),
        type: BottomNavigationBarType.fixed,
        elevation: 0,
        enableFeedback: false,
        //设置lable的颜色
        unselectedItemColor: const Color.fromARGB(255, 102, 102, 102),
        selectedItemColor: const Color.fromARGB(255, 80, 219, 142),
        // unselectedLabelStyle: const TextStyle(
        //     color: Color.fromARGB(255, 102, 102, 102), fontSize: 14),
        // selectedLabelStyle: const TextStyle(
        //     color: Color.fromARGB(255, 80, 219, 142), fontSize: 14),
        items: [
          _createTabbarItem(
              "home_n", "home_s", "首页"),
          _createTabbarItem(
              "news_n", "news_s", "题库"),
          _createTabbarItem(
              "study_n", "study_s", "学习"),
          _createTabbarItem(
              "news_n", "news_s", "资讯"),
          _createTabbarItem(
              "mine_n", "mine_s", "我的"),

        ],
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
    );
  }



  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }

  BottomNavigationBarItem _createTabbarItem(
      String icon, String activeIcon, String label) {
    return BottomNavigationBarItem(
        icon: Container(
          margin: const EdgeInsets.fromLTRB(0, 0, 0, 8),
          child: Image.asset(
            assetImage(icon),
            width: 20.adapt(),
            height: 15.adapt(),
          ),
        ),
        label: label,
        activeIcon: Container(
          margin: const EdgeInsets.fromLTRB(0, 0, 0, 8),
          child: Image.asset(
            assetImage(activeIcon),
            width: 20.adapt(),
            height: 15.adapt(),
          ),
        ));
  }
}
